﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using ProtoBuf.Message;
using Dict.DataModel;

namespace UI
{
    public class UIShopProduct
    {
        //定义完全按照ProtoBuf.Message.ShopItem 
        public string productId;        //商品id
        public int priority;    //排序
        public int canBuy;      //是否已购买
        public int dayLeftTimes;//今日剩余可购买次数
        public int dayTotalTimes;//今日总共可购买次数
        public List<BaseResource> productList;  //出售物品list :item,hero,coin,啥啥都有可能
        public List<BaseResource> exchangeList;   //兑换价格list
        public List<BaseResource> price;        //原价list
        public List<BaseResource> discount;     //折扣价list
        public MsgShopType msgShopType = MsgShopType.ItemShop;

        public void InitData(ShopItem shopitem, MsgShopType type = MsgShopType.ItemShop)
        {
            msgShopType = type;
            productId = shopitem.id;
            priority = shopitem.priority;
            canBuy = shopitem.canBuy;
            dayLeftTimes = shopitem.dayLeftTimes;
            dayTotalTimes = shopitem.dayTotalTimes;

            //出售物品list
            if (productList == null)
                productList = new List<BaseResource>();
            productList.Clear();
            for (int i = 0; i < shopitem.item.Count; i++)
            {
                BaseResource res = new BaseResource();
                res.id = shopitem.item[i].id;
                res.guid = shopitem.item[i].guid;
                res.num = shopitem.item[i].num;

                productList.Add(res);
            }

            //兑换价格list
            if (exchangeList == null)
                exchangeList = new List<BaseResource>();
            exchangeList.Clear();
            for (int i = 0; i < shopitem.exchangeList.Count; i++)
            {
                BaseResource res = new BaseResource();
                res.id = shopitem.exchangeList[i].id;
                res.guid = shopitem.exchangeList[i].guid;
                res.num = shopitem.exchangeList[i].num;

                exchangeList.Add(res);
            }

            //原价list
            if (price == null)
                price = new List<BaseResource>();
            price.Clear();
            for (int i = 0; i < shopitem.price.Count; i++)
            {
                BaseResource res = new BaseResource();
                res.id = shopitem.price[i].id;
                res.guid = shopitem.price[i].guid;
                res.num = shopitem.price[i].num;

                price.Add(res);
            }

            //折扣价list
            if (discount == null)
                discount = new List<BaseResource>();
            discount.Clear();
            for (int i = 0; i < shopitem.discount.Count; i++)
            {
                BaseResource res = new BaseResource();
                res.id = shopitem.discount[i].id;
                res.guid = shopitem.discount[i].guid;
                res.num = shopitem.discount[i].num;

                discount.Add(res);
            }
        }

        public TableItemShopPrice GetCurrentPrice()
        {
            return Dict.Blo.TableItemShopPriceBlo.GetShopPrice(productId, dayTotalTimes - dayLeftTimes + 1);
        }

    }
}

